<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class Qrcode extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    public  $typeEnum = [
        'publicCode' => '公众号',
        'H5' => 'H5',
        'applet' => '小程序',
    ];

    /**
     * 默认排序
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 可排序字段
     */
    public $sortable = [
        'created_at',
        'id',
        'user_id',
        'expire_time',
        'status',
        'scan',
    ];

    /**
     * 可搜索字段
     */
    public $searchable = [
        'third_type',
        'user_id',
        'ticket',
        'expire_time',
        'status',
        'url',
        'qrcode_url',
        'scan',
        'type',
    ];
    /**
     * 微信二维码管理表可批量赋值字段
     */
    protected $fillable = [
        'third_type',
        'user_id',
        'ticket',
        'expire_time',
        'status',
        'url',
        'qrcode_url',
        'scan',
        'type',
    ];

    /**
     * 二维码所属用户
     */
    public function codeUser(){
        return $this->belongsTo(User::class,'user_id','id');
    }
}
